﻿; (function (window, undefined, $) {

    $(document).ready(function () {

        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'New_ID', width: "5%", sortable: true, hide: false, align: 'left', iskey: true },
                     { display: '状态', name: 'Status', width: "5%", sortable: false, hide: true, align: 'left' },
                    { display: 'Id', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left'},
                    { display: '标题', name: 'MessTitle', width: "15%", sortable: false, align: 'left' },
                    { display: '类别', name: 'ClassId', width: "15%", sortable: false, align: 'left', process: proClass },
                    { display: '留言时间', name: 'CreateTime', width: "15%", sortable: false, align: 'left' },
                    //{ display: '回复人', name: 'MemberName', width: "15%", sortable: false, align: 'left' },
                    { display: '操作', name: 'Id', width: "15%", sortable: false, align: 'center', process: processOp }
              //{ display: '用户名', name: 'MemberId', width: "6.25%", sortable: false, align: 'left' },
            //{ display: '状态', name: 'Status', width: "6.25%", sortable: false, align: 'left' },
            ],
            sortname: "CreateTime",
            sortorder: "DESC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            if (cell[1] == 0) { 
                ops.push("&nbsp;已通过");
            }
            else if (cell[1] == 1) {
                ops.push("&nbsp;<a title='审核' href='javascript:;'  onclick=\"util.Audit('", value, "')\"><i class='fa fa-edit' ></i>审核</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            }
            else if (cell[1] == 2) {
                ops.push("&nbsp;已退回");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            }
            return ops.join("");
        }
        function proClass(value, cell) {
            if (value == 1) {
                return '安全问题';
            } else if (value == 2) {
                return '投标问题';
            } else if (value == 3) {
                return '关于汇金行';
            } else if (value == 4) {
                return '其他';
            }
        }
        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            location.href = url;
        });
        util.Edit = function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        };
        util.Audit = function (id) {
            var url = options.auditUrl + "/" + id;
            location.href = url;
        };
        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert("操作成功！");
                          xjgrid.Reload();
                      }
                      else {
                          alert("操作失败！");
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);
